<?php require_once(dirname(__FILE__) . '/inc/config.inc.php');
IsModelPriv('goodsorder');
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$tbname = '#@__tasktype';
if($id>0){
    $task_arr=$dosql->GetOne("select * from $tbname where id='$id'");
    if(is_array($task_arr) && isset($task_arr['id']) ){
        $task=$task_arr;
    }else{
        exit("id不存在");
    }
}else{
    exit("非法请求");
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>renl</title>
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="templates/js/jquery.min.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->

    <link href="layui/css/layui.css" rel="stylesheet" type="text/css" media="all"/>
    <script src="layui/layui.all.js"></script>
</head>
<body>


<style>
    .layui-upload-list img { max-width: 200px; height: auto;}
</style>
<div class="layui-form " lay-filter="layuiadmin-form-tags" id="layuiadmin-app-form-tags">


    <div class="layui-form-item mt10">
        <label class="layui-form-label">分类名称</label>
        <div class="layui-input-inline">
            <input type="hidden" id="id" name="id" value="<?php echo $task['id']?>"/>
            <input type="text" name="classname" value="<?php echo $task['classname']?>" lay-verify="required"
                   placeholder="请输入..." autocomplete="off" class="layui-input" >

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">缩略图</label>
        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" class="layui-btn upload-picurl" id="test-upload-normal">
                    上传图片
                </button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="test-upload-normal-img" src="/<?php echo $task['picurl']?>">
                    <p id="test-upload-demoText"></p>
                </div>
            </div>
            <input type="hidden" name="picurl" id="picurl" value="<?php echo $task['picurl']?>">

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">

            <input type="text" name="orderid" value="<?php echo $task['orderid']?>" lay-verify="required"
                   placeholder="请输入..." autocomplete="off" class="layui-input"> 正整数

        </div>
    </div>
    <div class="layui-form-item">

        <label class="layui-form-label">状态</label>

        <div class="layui-input-block">

            <input type="checkbox" name="checkinfo" lay-skin="switch"

                   lay-filter="component-form-switchTest" lay-text="已审|未审" <?php if($task['checkinfo']==1){echo "checked"; }?>>

        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="layuiadmin-app-tags-submit" value="确认" class="layui-btn">
        </div>
    </div>

</div>
<script>
    layui.use(['form', 'laydate', 'table', 'layedit', 'upload'], function () {
        var $ = layui.$,
            admin = layui.admin,
            element = layui.element,
            layer = layui.layer,
            view = layui.view,
            table = layui.table,
            laytpl = layui.laytpl,
            laydate = layui.laydate,
            layedit = layui.layedit,
            upload = layui.upload,
            form = layui.form;


        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test-upload-normal'
            //, url: '/upload/'
            , url: '../admin/upload.php' //接口url
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#test-upload-normal-img').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                if (res.code == 0) {
                    layer.msg("上传成功");
                    $("#picurl").val(res.image);
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#test-upload-demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
        layedit.set({
            uploadImage: {
                url: '../core/upload.php', //接口url
                type: 'post', //默认post
            }
        });
        form.render(null, 'layuiadmin-form-tags');
        //监听提交
        form.on('submit(layuiadmin-app-tags-submit)', function (data) {
            var field = data.field; //获取提交的字段
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url: "json/task/task_type_do.php",
                data: {
                    "field": field,
                    "action": 'update'
                },
                type: "POST",
                dataType: "json",
                success: function (res) {
                    console.log(res);
                    if (res.code == 0) {
                        console.log("返回成功");
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }

                }
            });
        });

    });
</script>
</body>
</html>